﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.Services;

namespace SalomonWebsite.Handler
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class GetFirstPageAd : IHttpHandler
    {
        public int PKID = 0;
        public string strCon = Global.Connection;
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            PKID = Convert.ToInt32(context.Request["pkid"]);
            context.Response.Write(GetFirstPageAdByPKID(strCon, PKID));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        public string GetFirstPageAdByPKID(string strCon,int PKID) 
        {
            string result = "";
            DataTable dt = Bll.CategoryAd.Single(strCon, PKID);
            
            if (dt != null && dt.Rows.Count > 0)
            {
                result = "{\"Total\":\"" + dt.Rows.Count + "\",\"List\":[";
                result += " {\"AdTitle\": \"" + dt.Rows[0]["AdTitle"].ToString() + "\"," +
                                   " \"ImgURL\": \"" + dt.Rows[0]["ImgURL"].ToString() + "\"," +
                                   " \"Description\": \"" + dt.Rows[0]["Description"].ToString() + "\"}";
                result += "]}";
            }
            return result;
        }
    }
}
